home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MEMORY.SWG / 0003_CMOSSTUF.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  9KB  |  177 lines

  1. (*******************************************************************)
  2.  Program SaveCMOS;              { Compiler: Turbo & Quick Pascal    }
  3. {                                                                   }
  4. { File name: SaveCMOS.PAS       coded: Mar.3.1993, Greg Vigneault   }
  5. {                                                                   }
  6. { This utility will read the entire contents of the CMOS RAM, and   }
  7. { save it to a File.  Invoke this Program as...                     }
  8. {                                                                   }
  9. {               SAVECMOS <Filename>                                 }
  10. {                                                                   }
  11.  Uses   Crt;                        { import ReadKey                }
  12.  Const  AddressRTC  = $70;          { RTC register address latch    }
  13.         DataRTC     = $71;          { RTC register data             }
  14.         AStatusRTC  = $0A;          { RTC status register A         }
  15.  Var    tempCMOS,
  16.         RegCMOS     : Byte;                     { RTC register      }
  17.         MapCMOS     : Array [0..63] of Byte;    { RTC CMOS reg map  }
  18.         OutFile     : File;                     { saved CMOS data   }
  19.         ch          : Char;                     { For user input    }
  20.         FResult     : Integer;                  { check File Write  }
  21. (*-----------------------------------------------------------------*)
  22.  Function ReadCMOS( RegCMOS :Byte ) :Byte;
  23.     begin
  24.         RegCMOS := RegCMOS and $3F;     { don't set the NMI bit     }
  25.         if (RegCMOS < AStatusRTC) then  { wait For end of update?   }
  26.             Repeat
  27.                 Port[AddressRTC] := AStatusRTC;     { read status   }
  28.             Until (Port[DataRTC] and $80) <> 0;     { busy bit      }
  29.         Port[AddressRTC] := RegCMOS;    { tell RTC which register   }
  30.         ReadCMOS := Port[DataRTC];      { and read in the data Byte }
  31.     end {ReadCMOS};
  32. (*-----------------------------------------------------------------*)
  33.  Procedure HelpExit;
  34.     begin   WriteLn; WriteLn( 'Usage: SAVECMOS <Filename>' );
  35.             WriteLn( CHR(7) );  Halt(1);
  36.     end {HelpExit};
  37. (*-----------------------------------------------------------------*)
  38.  begin
  39.     WriteLn; WriteLn( 'SaveCMOS v0.1  Greg Vigneault' ); WriteLn;
  40.     if (ParamCount <> 1) then HelpExit;
  41.     Assign( OutFile, ParamStr(1) );
  42.     {$i-}  Reset( OutFile, SizeOf(MapCMOS) );  {$i+}
  43.     if (IoResult = 0) then begin
  44.         Repeat
  45.           Write('File ',ParamStr(1),' exists! OverWrite? (Y/N): ',#7);
  46.           ch := UpCase( ReadKey );  WriteLn;
  47.         Until (ch in ['Y','N']);
  48.         if (ch = 'N') then begin WriteLn('ABORTED'); Halt(2); end;
  49.     end;
  50.     ReWrite( OutFile, SizeOf(MapCMOS) );  WriteLn;
  51.     For RegCMOS := 0 to 63 do MapCMOS[RegCMOS] := ReadCMOS(RegCMOS);
  52.     MapCMOS[AStatusRTC] := MapCMOS[AStatusRTC] and $7F; { clear UIP }
  53.     BlockWrite( OutFile, MapCMOS, 1, FResult );
  54.     if (FResult <> 1) then begin
  55.         WriteLn( 'Error writing to ',ParamStr(1),'!',#7 );
  56.         Close( OutFile );   Halt(3);
  57.     end;
  58.     FillChar( MapCMOS, SizeOf(MapCMOS), 0 );
  59.     Reset( OutFile, SizeOf(MapCMOS) );
  60.     BlockRead( OutFile, MapCMOS, 1, FResult );
  61.     if (FResult <> 1) then begin
  62.         WriteLn( 'Error reading from ',ParamStr(1),'!',#7 );
  63.         Close( OutFile );   Halt(4);
  64.     end;
  65.     Close(OutFile);
  66.     For RegCMOS := 10 to 63 do begin { don't include time in verify }
  67.         if (RegCMOS = AStatusRTC) then
  68.             MapCMOS[RegCMOS] := MapCMOS[RegCMOS] and $7F;
  69.         if (MapCMOS[RegCMOS] <> ReadCMOS(RegCMOS)) then begin
  70.             WriteLn('!!! Error: can''t verify File contents !!!');
  71.             WriteLn(#7#7#7#7#7); Halt(5);
  72.         end;
  73.     end;
  74.     WriteLn('! The CMOS RAM has now been saved in ',ParamStr(1),#7);
  75.  end {SaveCMOS}.
  76. (*******************************************************************)
  77.  
  78.  Greg_
  79.  
  80.  Mar.03.1993.Toronto.Canada.         greg.vigneault@bville.gts.org
  81. ---
  82.  ■ QNet3ß ■ City2City / 1/0/11 / Baudeville BBS / Toronto / 416-283-0114
  83. <<<>>>
  84.  
  85.  
  86. Date: 03-04-93 (03:03)              Number: 127 of 160 (Echo)
  87.   To: CHRIS LAUTENBACH              Refer#: NONE
  88. From: GREG VIGNEAULT                  Read: 03-05-93 (17:02)
  89. Subj: TP: LOADCMOS SOURCE CODE      Status: PUBLIC MESSAGE
  90. Conf: C-ProgramMING (368)        Read Type: GENERAL (+)
  91.  
  92. (*******************************************************************)
  93.  Program LoadCMOS;              { Compiler: Turbo & Quick Pascal    }
  94. {                                                                   }
  95. { File name: LoadCMOS.PAS       coded: Mar.3.1993, Greg Vigneault   }
  96. {                                                                   }
  97. {               LOADCMOS <Filename>                                 }
  98. {                                                                   }
  99.  Uses   Crt;                        { import ReadKey                }
  100.  Const  AddressRTC      = $70;      { RTC register address latch    }
  101.         DataRTC         = $71;      { RTC register data             }
  102.         AStatusRTC      = $0A;      { RTC status register A         }
  103.         BStatusRTC      = $0B;      { RTC status register B         }
  104.         CStatusRTC      = $0C;      { RTC status register C         }
  105.         DStatusRTC      = $0D;      { RTC status register D         }
  106.         SecondsRTC      = 0;        { seconds       (BCD, 0..59)    }
  107.         MinutesRTC      = 2;        { minutes       (BCD, 0..59)    }
  108.         HoursRTC        = 4;        { hours         (BCD, 0..23)    }
  109.         WeekDayRTC      = 6;        { day of week   (1..7)          }
  110.         DayOfMonthRTC   = 7;        { day of month  (BCD, 1..31)    }
  111.         MonthRTC        = 8;        { month         (BCD, 1..12)    }
  112.         YearRTC         = 9;        { year          (BCD, 0..99)    }
  113.  Var    RegCMOS     : Byte;                     { RTC register      }
  114.         MapCMOS     : Array [0..63] of Byte;    { RTC CMOS reg map  }
  115.         ChkSumCMOS  : Integer;                  { CMOS checksum     }
  116.         InFile      : File;                     { saved CMOS data   }
  117.         ch          : Char;                     { For user input    }
  118.         FResult     : Integer;                  { check File Write  }
  119. (*-----------------------------------------------------------------*)
  120.  Procedure WriteCMOS( RegCMOS, Value :Byte );
  121.     Var temp : Byte;
  122.     begin
  123.         if not (RegCMOS in [0,1,CStatusRTC,DStatusRTC]) then
  124.         begin
  125.             if (RegCMOS < CStatusRTC) then begin
  126.                 Port[AddressRTC] := BStatusRTC;
  127.                 temp := Port[DataRTC] or $80;       { stop the clock}
  128.                 Port[AddressRTC] := BStatusRTC;
  129.                 Port[DataRTC] := temp;
  130.             end;
  131.             Port[AddressRTC] := RegCMOS and $3F;    { select reg    }
  132.             Port[DataRTC] := Value;                 { Write data    }
  133.             if (RegCMOS < CStatusRTC) then begin
  134.                 Port[AddressRTC] := BStatusRTC;
  135.                 temp := Port[DataRTC] and not $80;  { enable clock  }
  136.                 Port[AddressRTC] := BStatusRTC;
  137.                 Port[DataRTC] := temp;
  138.             end;
  139.         end;
  140.     end {WriteCMOS};
  141. (*-----------------------------------------------------------------*)
  142.  Procedure HelpExit;
  143.     begin   WriteLn; WriteLn( 'Usage: LOADCMOS <Filename>' );
  144.             WriteLn( CHR(7) );  Halt(1);
  145.     end {HelpExit};
  146. (*-----------------------------------------------------------------*)
  147.  begin
  148.     WriteLn; WriteLn( 'LoadCMOS v0.1  Greg Vigneault' ); WriteLn;
  149.     if (ParamCount <> 1) then HelpExit;
  150.     Assign( InFile, ParamStr(1) );
  151.     {$i-}  Reset( InFile, SizeOf(MapCMOS) );  {$i+}
  152.     if (IoResult <> 0) then begin
  153.           Write('Can''t find ',ParamStr(1),'!',#7);
  154.           Halt(1);
  155.     end;
  156.     FillChar( MapCMOS, SizeOf(MapCMOS), 0 );        { initialize    }
  157.     BlockRead( InFile, MapCMOS, 1, FResult );       { saved CMOS    }
  158.     Close(InFile);
  159.     if (FResult <> 1) then begin
  160.         WriteLn('! Error reading File',#7);
  161.         Halt(2);
  162.     end;
  163.     MapCMOS[AStatusRTC] := MapCMOS[AStatusRTC] and $7F;
  164.     ChkSumCMOS := 0;                                { do checksum   }
  165.     For RegCMOS := $10 to $2D
  166.         do ChkSumCMOS := ChkSumCMOS + Integer( MapCMOS[RegCMOS] );
  167.     if (Hi(ChkSumCMOS) <> MapCMOS[$2E])
  168.     or (Lo(ChkSumCMOS) <> MapCMOS[$2F]) then begin
  169.         WriteLn('!!! CheckSum error in ',ParamStr(1) );
  170.         WriteLn(#7#7#7#7#7);  Halt(2);
  171.     end;
  172.     For RegCMOS := AStatusRTC to 63
  173.         do WriteCMOS( RegCMOS, MapCMOS[RegCMOS] );
  174.     WriteLn('! The CMOS RAM has been restored from ',ParamStr(1),#7);
  175.  end {LoadCMOS}.
  176. (*******************************************************************)
  177.